
const ref = function (target, track) {
    if (!target) {
        throw Error("typeof of target is error");
    }
    else if (typeof target !== "object") {
        return target
    } else if (Reflect.ownKeys(target).length > 0) {
        return new Proxy(target, {
            set(target, prop, newVal, receiver) {
                let stop = false
                if (typeof track === 'function') {
                    if (track(newVal) === true) {
                        stop = false;
                    }
                }
                target[prop] = newVal;
                void (receiver)
                return !stop;
            },
            get(t, p) {
                return t[p]
            }
        })
    }
}


function customRef(target, call_back) {
    if (new.target) {
        return ref(target, call_back);
    }
    else {
        throw new Error("miss new");
    }

}



export {
    customRef
}